<template>
  <div class="view-fill">
    <div class="app-container-flex">
      <NewFullScreen
        v-model="showDialog"
        title="预出库单明细"
        @returnBack="returnBack"
      >
        <template v-slot:full-button> </template>
        <div class="model-panel">
          <div class="model-panel-title">
            <p>{{ $t('basic_information') }}</p>
          </div>
          <div class="model-panel-body">
            <basic-information :info="infoList"> </basic-information>
          </div>
        </div>

        <div class="model-panel">
          <div class="model-panel-title">
            <Tooltip :text="$t('detailInfo')" />
          </div>
          <div class="model-panel-body">
            <div class="flex_full_item">
              <!-- 表格 -->
              <page-table
                :refresh="tableInfo.refresh"
                :init-curpage="tableInfo.initCurpage"
                v-model:data="tableInfo.data"
                :pager="false"
                :check-box="false"
                :tab-index="true"
                :field-list="tableInfo.fieldList"
                :handle="tableInfo.handle"
              >
              </page-table>
            </div>
          </div>
        </div>
      </NewFullScreen>
      <individual-details
        v-if="showIndividualDetails"
        v-model:show-dialog="showIndividualDetails"
        :query="paramsIndividual"
        :info="productInfo"
      ></individual-details>
    </div>
  </div>
</template>


<script setup name="hisPreExportOrderDetail">
import { detailPreExportOrderPage, getPreExportOrderDetailAll } from '@/api/his'
import { detailDepotStockQuery } from '@/api/dataQuery'
import IndividualDetails from '@/views/dataQuery/depotStockQuery/IndividualDetails'

const { proxy } = getCurrentInstance()
const emit = defineEmits()
const Tooltip = defineAsyncComponent(() => import('@/components/Tooltip/index'))

const props = defineProps(['visible', 'orderId'])

const infoList = reactive({
  data: {},
  fieldList: [
    { label: '预出入单号', value: 'orderNo', type: 'text' },
    { label: '计费组合码', value: 'combinationNum', type: 'text' },
    { label: '执行科室', value: 'performedDeptName', type: 'text' },
    { label: '业务类型', value: 'businessTypeValue', type: 'text' },
    { label: '状态', value: 'statusValue', type: 'text' },
    { label: '创建人', value: 'createUserName', type: 'text' },
    { label: '创建时间', value: 'createTime', type: 'text' },
    { label: '备注', value: 'remark', type: 'text' },
  ],
})
// 过滤相关配置
const filterInfo = reactive({
  sortArr: [],
  copyQueryMap: {},
  query: {
    customizeUserVO: {},
    queryMap: {},
    queryParams: {},
  },
  searchList: [],
  searchBtn: [],
  btnList: [],
})
// 表格相关
const tableInfo = reactive({
  refresh: 1,
  initCurpage: 1,
  data: [],
  fieldList: [],
  handle: {
    fixed: 'right',
    label: '操作',
    width: '100',
    btList: [
      {
        label: '库存个体详情',
        event: individualDetails,
        show: true,
      },
    ],
  },
})
const showDialog = computed({
  get() {
    return props.visible
  },
  set(newValue) {
    emits('update:visible', newValue) // 更新父组件shows
  },
})
const showIndividualDetails = ref(false)
const paramsIndividual = ref({})
const productInfo = ref({})

let obj = {
  productCode: {
    label: '产品编码',
    value: 'productCode',
    componentType: 'input',
    show: true,
    type: 'column',
    hidden: false,
  },
  productName: {
    label: '产品名称',
    value: 'productName',
    componentType: 'input',
    show: true,
    type: 'column',
    hidden: false,
  },
  productLot: {
    label: '批号',
    value: 'productLot',
    componentType: 'input',
    show: true,
    type: 'column',
    hidden: false,
  },
  productionDate: {
    label: '生产日期',
    value: 'productionDate',
    componentType: 'input',
    show: true,
    type: 'column',
    hidden: false,
  },
  validityDate: {
    label: '失效日期',
    value: 'validityDate',
    componentType: 'input',
    show: true,
    type: 'column',
    hidden: false,
  },
  barCode: {
    label: '条码',
    value: 'barCode',
    componentType: 'input',
    show: true,
    type: 'column',
    hidden: false,
  },
  uniqueCode: {
    label: '唯一码',
    value: 'uniqueCode',
    componentType: 'input',
    show: true,
    type: 'column',
    hidden: false,
  },
  factoryMainCode: {
    label: '原厂主码',
    value: 'factoryMainCode',
    componentType: 'input',
    show: true,
    type: 'column',
    hidden: false,
  },
  factorySubCode: {
    label: '原厂从码',
    value: 'factorySubCode',
    componentType: 'input',
    show: true,
    type: 'column',
    hidden: false,
  },
  qty: {
    label: '冻结数量',
    value: 'qty',
    componentType: 'input',
    show: true,
    type: 'column',
    hidden: false,
  },
  calcQty: {
    label: '冻结计算数量',
    value: 'calcQty',
    componentType: 'input',
    show: true,
    type: 'column',
    hidden: false,
  },
  consumeQty: {
    label: '消耗数量',
    value: 'consumeQty',
    componentType: 'input',
    show: true,
    type: 'column',
    hidden: false,
  },
  consumeCalcQty: {
    label: '消耗计算数量',
    value: 'consumeCalcQty',
    componentType: 'input',
    show: true,
    type: 'column',
    hidden: false,
  },
  thawQty: {
    label: '解冻数量',
    value: 'thawQty',
    componentType: 'input',
    show: true,
    type: 'column',
    hidden: false,
  },
  thawCalcQty: {
    label: '解冻计算数量',
    value: 'thawCalcQty',
    componentType: 'input',
    show: true,
    type: 'column',
    hidden: false,
  },
  price: {
    label: '单价',
    value: 'price',
    formatter: proxy.$fn.TripartiteMethod,
    show: true,
    type: 'column',
    hidden: false,
  },
  sumAmount: {
    label: '总金额',
    value: 'sumAmount',
    formatter: proxy.$fn.TripartiteMethod,
    show: true,
    type: 'column',
    hidden: false,
  },
}
tableInfo.fieldList = Object.values({
  ...obj,
})
getCustomize()

//个体详情
function individualDetails(row) {
  detailDepotStockQuery(row.depotStockId).then((resp) => {
    if (resp && resp.success) {
      paramsIndividual.value['id'] = {
        queryType: 'IN',
        queryCategory: 'AND',
        value: resp.data.id,
      }
      productInfo.value = resp.data

      showIndividualDetails.value = true
    }
  })
}
function getCustomize() {
  getMain()
  getList()
}
function getMain() {
  detailPreExportOrderPage(props.orderId).then((resp) => {
    if (resp && resp.success) {
      infoList.data = resp.data
    }
  })
}
function getList() {
  let parmas = {
    orderId: props.orderId,
  }
  getPreExportOrderDetailAll(parmas).then((resp) => {
    if (resp && resp.success) {
      tableInfo.data = resp.data
    }
  })
}
</script>

<style scoped></style>
